package com.example.administrator.zyfypt_211dsh.fragment;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.zyfypt_211dsh.R;
import com.example.administrator.zyfypt_211dsh.adapter.VideoAdapter;
import com.example.administrator.zyfypt_211dsh.bean.VideoBean;
import com.example.administrator.zyfypt_211dsh.iface.VideoListener;
import com.example.administrator.zyfypt_211dsh.lib.PagerSlidingTabStrip;
import com.example.administrator.zyfypt_211dsh.model.VideoModel;

import java.util.List;


/**
 * Created by Neusoft on 2017/4/9.
 */

public class Fragment3 extends Fragment {
    private View view;
    private Context context;
    private Fragment3_1 fragment3_1;
    private Fragment3_2 fragment3_2;
    private PagerSlidingTabStrip tabs;
    private DisplayMetrics dm;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        context = getActivity();
        if(view == null){
            view = inflater.inflate(R.layout.fragment3, null);
            initView(view);
        }
        return view;
    }

    private void initView(View view) {
        dm = getResources().getDisplayMetrics();
        ViewPager pager = (ViewPager) view.findViewById(R.id.pager);
        tabs = (PagerSlidingTabStrip) view.findViewById(R.id.tabs);
        pager.setAdapter(new MyPagerAdapter(getChildFragmentManager()));
        tabs.setViewPager(pager);
        setTabsValue();
    }

    private void setTabsValue() {
        // 设置Tab是自动填充满屏幕的
        tabs.setShouldExpand(true);
        // 设置Tab的分割线是透明的
        tabs.setDividerColor(Color.TRANSPARENT);
        // tabs.setDividerColor(Color.BLACK);
        // 设置Tab底部线的高度
        tabs.setUnderlineHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 1, dm));
        // 设置Tab Indicator的高度
        tabs.setIndicatorHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 4, dm));// 4
        // 设置Tab标题文字的大小
        tabs.setTextSize((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_SP, 16, dm)); // 16
        // 设置Tab Indicator的颜色
        tabs.setIndicatorColor(Color.parseColor("#45c01a"));// #45c01a
        // 设置选中Tab文字的颜色 (这是我自定义的一个方法)
        tabs.setSelectedTextColor(Color.parseColor("#45c01a"));// #45c01a
        // 取消点击Tab时的背景色
        tabs.setTabBackground(0);
    }
    public class MyPagerAdapter extends FragmentStatePagerAdapter {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }

        private final String[] titles = { "最热", "专题" };

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:

                    if (null == fragment3_1) {
                        fragment3_1 = new Fragment3_1();
                    }

                    return fragment3_1;

                case 1:

                    if (null == fragment3_2) {
                        fragment3_2 = new Fragment3_2();
                    }

                    return fragment3_2;

                default:
                    return null;
            }
        }

    }
}
